﻿using Castle.DynamicProxy;
using CNKI.TPI.Web.Base;
using CNKI.TPI.Web.Interface.Models;
using CNKI.TPI.Web.Search.IBLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;

namespace CNKI.TPI.Web.Interface.Areas.Resource.Controllers
{
    public class ExecuteNonQueryController : BaseApiController
    {
        private ISearchService searchService = null;
        public ExecuteNonQueryController(ISearchService searchService)
        {
            this.searchService = generator.CreateInterfaceProxyWithTarget<ISearchService>(searchService, new IInterceptor[] { new LogInterceptor() });
        }
        // GET api/getdocumentbysql/5
        public object Post()
        {
            OutputEntity result = new OutputEntity();
            try
            {
                HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
                HttpRequestBase request = context.Request;//定义传统request对象
                string sql = request.Form["sql"];

                int status = searchService.ExecuteNonQuery(sql);
                if (status == 0)
                {
                    result.Status = Status.Error;
                }
                else
                {
                    result.Status = Status.Success;
                    result.data = status;
                }
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
                result.Status = Status.Error;
                result.message = ex.Message;
            }
            return result;
        }
    }
}
